﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYCodeBase.WinForm;
using HYView;

namespace HYIndicateDimension.DrawLaneLine
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class DrawLaneLines : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication application = commandData.Application;
			if (!(application.ActiveUIDocument.Document.ActiveView is ViewPlan))
			{
				Result result = SwitchView.SetUsableView((CmdViewType)3, commandData);
				if (result != Result.Succeeded)
				{
					return result;
				}
			}
			if (this._hWndRevit == null)
			{
				IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
				this._hWndRevit = new WindowHandle(mainWindowHandle);
			}
			AppDrawLaneLines.DrawLines(application, this._hWndRevit);
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private WindowHandle _hWndRevit;
	}
}
